package org.come.npc;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import come.tool.JDialog.TiShiUtil;
import org.come.Frame.OptionsJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.ZhshuanfutujianJpanel;
import org.come.Jpanel.ZhuJpanel;
import org.come.action.NpcMenuAction;
import org.come.bean.ConfigureBean;
import org.come.entity.Goodstable;
import org.come.entity.Mount;
import org.come.entity.RoleSummoning;
import org.come.model.Configure;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.AnalysisString;
import org.come.until.UserMessUntil;

import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;

public class PetConversion implements NpcMenuAction {

	@Override
	public void menuControl(String type) {
		if("转生当前召唤兽".equals(type)){
			petTurnaround();
		}else if ("点化当前坐骑".equals(type)) {
			dianhuaMount();
		}else if ("点化当前召唤兽".equals(type)) {
			dianhuaPet();
		}else if("飞升当前参战神兽".equals(type)){
			revealPet();
		}else if("神兽学习技能".equals(type)){
			petLearnSkill();
		}else if(type.equals("确定购买幻肤吗?")){
			huanfuPet();
		}
	}
	/**神兽学习技能*/
	public void petLearnSkill(){
		ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
		Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
		Configure configure = item.get(new BigDecimal(1));
		int num = 9;
		if(configure.getZhsjngs()!=null) {
			num = Integer.parseInt(configure.getZhsjngs());
		}
		
		
		//判断当前是否有携带召唤兽
		if (RoleData.getRoleData().getLoginResult().getSummoning_id() ==null) {
			ZhuFrame.getZhuJpanel().addPrompt2("您并没有携带召唤兽!!!");
			return;
		}
		RoleSummoning pet=null;			
		for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
			if(UserMessUntil.getPetListTable().get(i).getSid().compareTo(RoleData.getRoleData().getLoginResult().getSummoning_id()) == 0){
				pet=UserMessUntil.getPetListTable().get(i);
				break;
			}
		}
		if (pet==null) {
            return;
        }
		//判断携带的召唤兽是否是神兽
		if (!"2".equals(pet.getSsn())&&!"3".equals(pet.getSsn())&&!"4".equals(pet.getSsn())) {
			ZhuFrame.getZhuJpanel().addPrompt2("您携带的召唤兽并不是神兽!!!");
			return;
		}
        if (RoleData.getRoleData().getLoginResult().getGold().compareTo(new BigDecimal(50000000))<0) {
    		ZhuFrame.getZhuJpanel().addPrompt2("金币不足!!!");
    		return;
		}
        if (pet.getFriendliness()<500000) {
        	ZhuFrame.getZhuJpanel().addPrompt2("您的神兽亲密值不足500000!!!");
        	return;
		}
        
        if (pet.getOpenSeal()<num) {
    		ZhuFrame.getZhuJpanel().addPrompt2("您的神兽技能格子还未解封!!!");
    		return;
		}
    	String sendmes = Agreement.getAgreement().userpetAgreement("SS|"+pet.getSid());
		SendMessageUntil.toServer(sendmes);	
	}
	/**飞升当前参战神兽*/
	public void revealPet(){
		//判断当前是否有携带召唤兽
		if (RoleData.getRoleData().getLoginResult().getSummoning_id() ==null) {
			ZhuFrame.getZhuJpanel().addPrompt2("您并没有携带召唤兽!!!");
			return;
		}
		RoleSummoning pet=null;			
		for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
			if(UserMessUntil.getPetListTable().get(i).getSid().compareTo(RoleData.getRoleData().getLoginResult().getSummoning_id()) == 0){
				pet=UserMessUntil.getPetListTable().get(i);
				break;
			}
		}
		if (pet==null) {
            return;
        }
		//判断携带的召唤兽是否是神兽
		if (!"3".equals(pet.getSsn())&&!"4".equals(pet.getSsn())) {
			ZhuFrame.getZhuJpanel().addPrompt2("您携带的召唤兽不是可飞升的神兽!!!");
			return;
		}
		//先判断金币是否足够
		if(RoleData.getRoleData().getLoginResult().getGold().compareTo(new BigDecimal(5000000)) <0){
			ZhuFrame.getZhuJpanel().addPrompt2("金币不足5000000两!");
			return;
		}	
		boolean bool = false;
		//判断条件是否够
		if(pet.getRevealNum() == 0){//第1次飞升
			if(pet.getGrade() >= 50) {
                bool = true;
            }
		}else if(pet.getRevealNum() == 1){//第2次飞升
		    if(pet.getGrade() >= 188) {
                bool = true;
            }
		}else if(pet.getRevealNum() == 2){//第3次飞升
			if(pet.getGrade() >= 316) {
                bool = true;
            }
		}
		if (!bool) {
			ZhuFrame.getZhuJpanel().addPrompt2("您的神兽 "+pet.getSummoningname()+" 不符合飞升的条件!");
			return;
		}		
		String sendmes = Agreement.getAgreement().userpetAgreement("FS|"+pet.getSid());
		SendMessageUntil.toServer(sendmes);
	}
	/**召唤兽点化*/
	public void dianhuaPet(){
        if (AnalysisString.lvltrue(RoleData.getRoleData().getLoginResult().getGrade())<=3) {
        	ZhuFrame.getZhuJpanel().addPrompt2("人物飞升后才能点化召唤兽");	
			return;
		}
		BigDecimal sid=RoleData.getRoleData().getLoginResult().getSummoning_id();
		RoleSummoning pet=null;
		if (sid!=null) {
			for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
				if (UserMessUntil.getPetListTable().get(i).getSid().longValue()==sid.longValue()) {
					pet=UserMessUntil.getPetListTable().get(i);
					break;
				}
			}
		}
		if (pet==null) {
			ZhuFrame.getZhuJpanel().addPrompt2("你没有参战的召唤兽！");	
			return;
		}
		if (pet.getGrade()!=543) {
			ZhuFrame.getZhuJpanel().addPrompt2("召唤兽等级不够");	
			return;
		}
		if (pet.getFriendliness()<2000000) {
			ZhuFrame.getZhuJpanel().addPrompt2("召唤兽亲密不够200万");	
			return;
		}
		String sendmes = Agreement.getAgreement().userpetAgreement("DH|"+pet.getSid());
		SendMessageUntil.toServer(sendmes);
	}
	/**转生当前召唤兽*/
	public void petTurnaround(){
		BigDecimal sid=RoleData.getRoleData().getLoginResult().getSummoning_id();
		RoleSummoning pet=null;
		if (sid!=null) {
			for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
				if (UserMessUntil.getPetListTable().get(i).getSid().longValue()==sid.longValue()) {
					pet=UserMessUntil.getPetListTable().get(i);
					break;
				}
			}
		}
		if (pet==null) {
			ZhuFrame.getZhuJpanel().addPrompt2("你没有参战的召唤兽！");	
			return;
		}
        if (pet.getTurnRount()>=RoleData.getRoleData().getLoginResult().getTurnAround()) {
    		ZhuFrame.getZhuJpanel().addPrompt2("快去升级吧!你快驾驭不你的召唤兽了");	
        	return;
		}
        if (pet.getTurnRount()>=3) {
        	ZhuFrame.getZhuJpanel().addPrompt2("最高到3转");	
			return;
		}
        if (RoleData.getRoleData().getLoginResult().getGold().compareTo(new BigDecimal(200000)) < 0) {
        	ZhuFrame.getZhuJpanel().addPrompt2("金币不足！");
        	return;
		}
        int lvl=pet.getGrade();
        int petTurn=pet.getTurnRount();
        if (petTurn==0) {
			if (lvl!=100) {
				ZhuFrame.getZhuJpanel().addPrompt2("你的召唤兽"+pet.getSummoningname()+"等级不够,还需多加历练!");
				return;
			}
			if(pet.getFriendliness()<100000){
				ZhuFrame.getZhuJpanel().addPrompt2("您的召唤兽与您的亲密值不足10万");
				return;
			}
		}else if (petTurn==1) {
			if (lvl!=221) {
				ZhuFrame.getZhuJpanel().addPrompt2("你的召唤兽"+pet.getSummoningname()+"等级不够,还需多加历练!");
				return;
			}
			if(pet.getFriendliness()<200000){
				ZhuFrame.getZhuJpanel().addPrompt2("您的召唤兽与您的亲密值不足20万");
				return;
			}
		}else if (petTurn==2) {
			if (lvl!=362) {
				ZhuFrame.getZhuJpanel().addPrompt2("你的召唤兽"+pet.getSummoningname()+"等级不够,还需多加历练!");
				return;
			}
			if(pet.getFriendliness()<500000){
				ZhuFrame.getZhuJpanel().addPrompt2("您的召唤兽与您的亲密值不足50万");
				return;
			}
		}
        String sendmes = Agreement.getAgreement().userpetAgreement("DH|"+pet.getSid());
		SendMessageUntil.toServer(sendmes);
	}
	/**点化当前坐骑*/
	public void dianhuaMount(){
		if (ImageMixDeal.userimg.getRoleShow().getMount_id()==0) {ZhuFrame.getZhuJpanel().addPrompt2("你当前未骑坐骑");return;}
		int mount_id=ImageMixDeal.userimg.getRoleShow().getMount_id();
		Mount mount=null;
		List<Mount> mounts=ZhuJpanel.getListMount();
		if (mounts!=null) {
			for (int i = 0; i < mounts.size(); i++) {
				if (mounts.get(i).getMountid()==mount_id) {
					mount=mounts.get(i);
					break;
				}
			}
		}
//		坐骑点化功能，点化要求当前坐骑要求必须满等级，满熟练，
//		点化后等级将退回0级，熟练度清0，坐骑点化后，管制加1，各项初值均提升3，熟练度上限增加为150000,管制范围扩大，能力更强。
		if (mount==null) {
			ZhuFrame.getZhuJpanel().addPrompt2("你当前未骑坐骑");	
			return;
		}
		if (mount.getMountlvl()!=100||mount.getProficiency()<100000) {
			ZhuFrame.getZhuJpanel().addPrompt2("坐骑不符合点化要求");	
			return;
		}
		if (mount.getSid()!=null||mount.getOthrersid()!=null||mount.getSid3()!=null||mount.getSid4()!=null||mount.getSid5()!=null) {
			ZhuFrame.getZhuJpanel().addPrompt2("坐骑还管制着召唤兽");	
			return;
		}
		String sendmes = Agreement.getAgreement().usermountAgreement("DH|"+mount.getMid());
		SendMessageUntil.toServer(sendmes);
	}
	public void huanfuPet() {
		if (RoleData.getRoleData().getLoginResult().getSummoning_id() == null) {
			ZhuFrame.getZhuJpanel().addPrompt2("召唤兽参战后才能幻肤!!!");
			return;
		}
		RoleSummoning pet = null;
		for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
			if (UserMessUntil.getPetListTable().get(i).getSid().compareTo(RoleData.getRoleData().getLoginResult().getSummoning_id()) == 0) {
				pet = UserMessUntil.getPetListTable().get(i);
				break;
			}
		}
		if (RoleData.getRoleData().getLoginResult().getCodecard().compareTo(new BigDecimal(88888)) < 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("仙玉不足88888!");
			return;
		}
		Goodstable ltrGoods = ZhshuanfutujianJpanel.getGoodType(Long.parseLong(ZhshuanfutujianJpanel.good.get(pet.getSummoningid()+"")));
		int   num = ltrGoods == null ? 0 : ltrGoods.getUsetime();
		if (num<100){
			ZhuFrame.getZhuJpanel().addPrompt2("物品不足");
			return;
		}
		boolean bool = false;
		//判断条件是否够
		if (Objects.requireNonNull(pet).getRevealNum() == 0) {//第1次幻化
			if (pet.getGrade() >= 0) {
				bool = true;
			}
//		} else if (pet.getRevealNum() == 1) {//第2次幻化
//			if (pet.getGrade() >= 400) {
//				bool = true;
//			}
		}
		if (!bool) {
			ZhuFrame.getZhuJpanel().addPrompt2("您的神兽 " + pet.getSummoningname() + " 已经幻化过了!");
			return;
		}

		//判断当前是否有携带召唤兽
		int petid = Integer.parseInt(pet.getSummoningid());
		if (petid != 200185 && petid != 200188 && petid != 200099  //飞轩 莲生 浪淘沙
				&& petid != 200100 && petid != 200097 && petid != 200101 //五叶 垂云叟 颜如玉
				&& petid != 200098 && petid != 200116 && petid != 200184 //范式之魂 年兽 灵听
				&& petid != 200117 && petid != 200140 && petid != 200123 //画中仙 孟极 白泽
				&& petid != 200192 && petid != 200124 && petid != 200191 //幻方 龙马 新手龙马
				&& petid != 754 && petid != 755 && petid != 756 //大娃 二娃 三娃
				&& petid != 757 && petid != 758 && petid != 759 //四娃 五娃 六娃
				&& petid != 760 && petid != 761 && petid != 200224 //七娃 葫芦小金刚 白龙帝
				&& petid != 200367 && petid != 200368 && petid != 200369 //天蓬元帅 孔雀仙子 梅比斯耶
				&& petid != 200370 && petid != 200371 && petid != 200380 //南海人鱼 超级剑灵 乘黄
				&& petid != 811 && petid != 812 ) {  //龙小侠 赤血龙马
			//petid != 200188&& petid != 6002 这个格式是 前面对应旧召唤兽ID 后面对应新召唤兽ID
			String msg = "该召唤兽没有幻肤！";
			ZhuFrame.getZhuJpanel().addPrompt2(msg);
			return;
		}
		ltrGoods.goodxh(100);
		String sendmes = Agreement.getAgreement().userpetAgreement("HF|" + pet.getSid()+"|"+ltrGoods.getRgid());
		SendMessageUntil.toServer(sendmes);

	}
}
